/**
 * 仓库
 *
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/1/15
 */
package com.sxf.crm.repository;


import com.sxf.crm.entity.Industry;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface IndustryRepository extends JpaRepository<Industry, Long> {
    List<Industry> findByParentIsNull();
    
    List<Industry> findByParentId(Long parentId);
    
    @Query("SELECT i FROM Industry i WHERE i.level = 1 ORDER BY i.name")
    List<Industry> findAllRootIndustries();
    
    @Query("SELECT i FROM Industry i WHERE i.parent.id = ?1 ORDER BY i.name")
    List<Industry> findChildrenByParentId(Long parentId);
    
    @Query("SELECT i FROM Industry i WHERE i.path LIKE ?1% ORDER BY i.path")
    List<Industry> findByPathStartingWith(String path);
} 